<div class="row">
  <div class="col-md-9">
    <div class="panel panel-default">
      <div class="panel-heading"><%= t("users.personal_information")%></div>
      <div class="panel-body">
        <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, enctype:  "multipart/form-data" }) do |f| %>
        <%= render "shared/error_messages", target: resource if params[:by].blank? %>
        <%= f.input :name %>
        <%= f.input :avatar %>
        <%= f.input :email, input_html: { class: "span4", disabled: (!resource.email.blank?) } %>
        <div class="form-group">
          <div class="col-sm-10 col-sm-offset-2">
            <div class="checkbox">
              <label for="user_email_public" class="checkbox"><%= f.check_box :email_public %> <%= t("users.email_permission")%></label>
            </div>
          </div>
        </div>
        <%= f.input :location  %>
        <%= f.input :company %>
        <div class="form-group">
          <%= f.label :github %>
          <div class="col-sm-10">
            <div class="input-group">
              <span class="input-group-addon">https://github.com/</span>
              <%= f.text_field :github, type: :email, class: "form-control", placeholder: "yourname" %>
            </div>
          </div>
        </div>
        <div class="form-group">
          <%= f.label :twitter %>
          <div class="col-sm-10">
            <div class="input-group">
              <span class="input-group-addon">http://twitter.com/</span>
              <%= f.text_field :twitter, type: :email, class: "form-control", placeholder: "yourname" %>
            </div>
          </div>
        </div>
        <%= f.input :website, type: :url, input_html: { placeholder: "http://" } %>
        <%= f.input :tagline %>
        <%= f.input :bio, as: :text, input_html: { class: "xxlarge", rows: "6" } %>
        <div class="form-group">
          <div class="col-sm-10 col-sm-offset-2">
            <button type="submit" class="btn btn-primary" data-disable-with="<%= t("common.saving") %>"><%= t("users.update_profile")%></button>
          </div>
        </div>
        <% end %>
      </div>
    </div>
    <div class="panel panel-default">
      <div class="panel-heading"><%= t("users.edit_password")%></div>
      <div class="panel-body">
        <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name, by: :pwd), html: { method: :put }) do |f| %>
        <%= render "shared/error_messages", target: resource if params[:by] == "pwd" %>
        <input type="hidden" name="by" value="pwd" />
        <%= f.input :current_password %>
        <%= f.input :password %>
        <%= f.input :password_confirmation %>
        <div class="form-group">
          <div class="col-sm-10 col-sm-offset-2">
            <%= f.submit t("users.update_password"), class: "btn btn-success", 'data-disable-with' => t("common.saving") %>
          </div>
        </div>
        <% end %>
      </div>
    </div>
  </div>
  <div class="sidebar col-md-3">
    <div class="panel panel-default" style="text-align:center;">
      <div class="panel-body">
        <%= user_avatar_tag(@user, :large, link: false) %>
      </div>
    </div>
    <div class="panel panel-default">
      <div class="panel-heading"><%= t("users.bind_another_account")%></div>
      <ul class="list-group">
        <% ["github"].each do |provider| %>
        <li class="list-group-item">
          <% if @user.bind? provider %>
          <%= t("omniauth.#{provider}") %>
          <%= link_to(raw('<i class="fa fa-remove"></i>'),"/account/auth/#{provider}/unbind", rel: "twitsy", title: "点击解除绑定", method: 'delete' )%>
          <% else %>
          <%= link_to(t("omniauth.#{provider}"), "/account/auth/#{provider}", rel: "twitsy", title: "点击绑定" )%>
          <% end %>
        </li>
        <% end %>
      </ul>
    </div>

    <div class="panel panel-default">
      <ul class="list-group">
        <li class="list-group-item"><%= link_to t("users.manage_my_apps"), oauth_applications_path %></li>
      </ul>
    </div>


    <div class="panel panel-default">
      <div class="panel-heading"><%= t("users.private_key")%></div>
      <div class="panel-body">
        <div class="form-group">
          <input id="private_token" class="form-control" value="<%= @user.private_token %>" readonly="readonly">
        </div>
        <div class="buttons">
          <a href="#" class="btn btn-default btn-sm" id="update_private_token"><%= t("users.replace_token")%></a> <span class="help-inline"><%= t("users.token_usage")%></span>
        </div>
      </div>
    </div>
    <div class="panel panel-default">
      <div class="panel-heading"><%= t("users.delete_account")%></div>
      <div class="panel-body">
        <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :method => :delete) do |f| %>
        <%= render "shared/error_messages", :target => resource if params[:by] == "destroy" %>
        <input type="hidden" name="by" value="destroy" />
        <div class="form-group">
          <%= f.password_field :current_password, class: "form-control", placeholder: t("users.confirm_delete_account") %>
        </div>
        <%= f.submit t("users.ensure_to_delete"), :class => "btn btn-danger btn-sm btn-block", 'data-disable-with' => t("common.submitting") %>
        <% end %>
      </div>
    </div>
  </div>
</div>
<% content_for :scripts do %>
<script type="text/javascript">
$(document).ready(function(){
$("#update_private_token").click(function(){
$.post("<%= update_private_token_account_path %>",function(re){
$("#private_token").val(re);
});
return false;
})
});
</script>
<% end %>
